package com.minglead.springboot.platform.sys.entity;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.validator.constraints.Length;

import com.minglead.springboot.common.persistence.TreeEntity;
import com.minglead.springboot.common.utils.StringUtils;
import com.minglead.springboot.platform.sys.bean.CommonBean;
/**
 * 区域Entity
 */
public class Area extends TreeEntity<Area> {

	private static final long serialVersionUID = 1L;
	private String code; 	// 区域编码
	private String name; 	// 区域名称
	private Integer sort;		// 排序
	private String type; 	// 区域类型（1：国家；2：省份、直辖市；3：地市；4：区县）
	
	private String typeValue;
	
	
	public Area(){
		super();
		this.sort = 30;
	}

	public Area(String id){
		super(id);
	}
	
//	@JsonBackReference
//	@NotNull
	public Area getParent() {
		return parent;
	}

	public void setParent(Area parent) {
		this.parent = parent;
	}

	//（1：国家；2：省份、直辖市；3：地市；4：区县）
	public static List<CommonBean> getTypeList(){	
		
		List<CommonBean> list = new ArrayList<CommonBean>();		
		CommonBean c_1 = new CommonBean();
		c_1.setValue("1");
		c_1.setLabel(Area.getTypeLabel(c_1.getValue()));	
	

		CommonBean c_2 = new CommonBean();
		c_2.setValue("2");
		c_2.setLabel(Area.getTypeLabel(c_2.getValue()));	
		
		CommonBean c_3 = new CommonBean();
		c_3.setValue("3");
		c_3.setLabel(Area.getTypeLabel(c_3.getValue()));	
		
		CommonBean c_4 = new CommonBean();
		c_4.setValue("4");
		c_4.setLabel(Area.getTypeLabel(c_4.getValue()));	

		
		list.add(c_1);
		list.add(c_2);
		list.add(c_3);
		list.add(c_4);
		return list;
	}


	public static String getTypeLabel(String type){
		if(StringUtils.isEmpty(type))
			return "null";
		if("1".equals(type)){
			return "国家";
		}else if("2".equals(type)){
			return "省份、直辖市";
		}else if("3".equals(type)){
			return "地市";
		}else if("4".equals(type)){
			return "区县";
		}else{
			return "未知状态";
		}
	}

	public String getTypeValue() {
		return typeValue;
	}

	public void setTypeValue(String typeValue) {
		this.typeValue = typeValue;
	}

	@Length(min=1, max=1)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}

	@Length(min=0, max=100)
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	
	@Override
	public String toString() {
		return name;
	}
}